<template>
  <!-- 订单列表组件 -->
  <div class="order_cont">
    <!-- 面包屑导航栏区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区域 -->
    <el-card>
      <!-- 搜索框 -->
      <el-row>
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="searchOrder">
            <el-button slot="append" icon="el-icon-search" @click="searchOrderList"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表格展示区域 -->
      <el-table :data="orderList" border style="width: 100%">
        <el-table-column type="index" width="50">
        </el-table-column>
        <el-table-column prop="order_number" label="订单编号" width="210">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格/元">
        </el-table-column>
        <el-table-column prop="pay_status" label="是否付款">
          <template slot-scope="scope">
            <el-tag type="success" size="mini" v-if="scope.row.pay_status === 1">已付款</el-tag>
            <el-tag type="danger" size="mini" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货">
        </el-table-column>
        <!-- 将时间戳转换成时间-过滤器 -->
        <el-table-column prop="create_time" label="下单时间" width="165">
          <template slot-scope="scope">
            {{scope.row.create_time | timeTransition}}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="145">
          <template slot-scope="scope">
            <el-button type="primary" icon="el-icon-edit" size="mini" @click="alterDialogBut(scope.row)"></el-button>
            <el-button type="success" icon="el-icon-location" size="mini" @click="transportDialogBut(scope.row)">
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页区域 -->
      <el-pagination :background="true" @size-change="OrderHandleSizeChange" @current-change="OrderHandleCurrentChange"
        :current-page="OrderQueryInfo.pagenum" :page-sizes="[5, 10, 15, 20]" :page-size="OrderQueryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper" :total="orderTotal">
      </el-pagination>
    </el-card>
    <!-- 操作块-编辑-修改地址对话框 -->
    <el-dialog title="修改地址" :visible.sync="alterDialogBool" width="50%" :before-close="alterHandleClose"
      :close-on-click-modal="false">
      <!-- 表单区域 -->
      <el-form :model="alterRuleForm" :rules="alterFormRules" ref="alterFormRef" label-width="100px" class="add_form">
        <el-form-item label="省市区/县" prop="city">
          <!-- 省市区/县-联级选择框-（外部引入的citydata.js） -->
          <el-cascader expand-trigger="hover" :options="cityData" v-model="alterRuleForm.city"
            @change="cityDataHandleChange" :clearable="true">
          </el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="location">
          <el-input v-model="alterRuleForm.location"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="alterHandleClose">取 消</el-button>
        <el-button type="primary" @click="alterHandleClose">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 操作块-位置-物流信息的的对话框transport -->
    <el-dialog title="物流信息" :visible.sync="transportBool" width="50%" :before-close="transportHandleClose"
      :close-on-click-modal="false">
      <!-- 物流时间戳区域 -->
      <el-timeline :reverse="transportReverse">
        <el-timeline-item v-for="item in transportList" :key="item.id" :timestamp="item.ftime">
          {{item.context}}
        </el-timeline-item>
      </el-timeline>
      <span slot="footer" class="dialog-footer">
        <!-- <el-button @click="transportHandleClose">取 消</el-button> -->
        <el-button type="primary" @click="transportHandleClose">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import cityData from './citydata.js'

  export default {
    data() {
      return {
        // 订单列表的请求参数
        OrderQueryInfo: {
          query: '',
          pagenum: 1, // 当前页码
          pagesize: 5 // 每页展示条数
        },
        // 订单列表总数据条数
        orderTotal: 0,
        // 订单列表的数组
        orderList: [],
        // 搜索框的数据绑定
        searchOrder: '',
        // 操作块-编辑-弹出的对话框显示与否
        alterDialogBool: false,
        // 操作块-编辑-表单数据
        alterRuleForm: {
          location: '',
          city: []
        },
        // 操作块-编辑-表单数据校验
        alterFormRules: {
          location: [{
            required: true,
            message: '请填写详细地址'
          }],
          city: [{
            required: true,
            message: '请选择省市区/县'
          }]
        },
        // 操作块-编辑-表单的省市区/县
        cityData: cityData,
        // 操作块-位置-物流信息对话框显示与否
        transportBool: false,
        // 操作块-位置-物流信息数据（接口bug假数据）
        transportList: {},
        // 操作块-位置-物流信息显示正序false或倒序true
        transportReverse: true,

      }
    },
    created() {
      this.getOrderList()
    },
    methods: {
      // 获取订单列表的数据
      async getOrderList() {
        let {
          data: res
        } = await this.$http.get(`orders`, {
          params: this.OrderQueryInfo
        })

        if (res.meta.status === 200) {
          this.orderList = res.data.goods
          this.orderTotal = res.data.total
        } else {
          this.$message.error(" 订单列表获取失败！")
        }
      },


      // 点击分页-当前页码回调
      OrderHandleCurrentChange(pagenum) {
        this.OrderQueryInfo.pagenum = pagenum
        this.getOrderList()
      },


      // 点击分页-每页显示条数回调
      OrderHandleSizeChange(pagesize) {
        this.OrderQueryInfo.pagesize = pagesize
        this.getOrderList()
      },


      // 搜索框的搜索按钮回调
      searchOrderList() {
        this.$message.error("抱歉，查询订单数据的请求错误！")
        // -------------- 问题：接口不行 --------------
        // this.OrderQueryInfo.query = this.searchOrder
        // this.getOrderList()
      },


      // 操作块-编辑-修改地址对话框显示与否
      alterDialogBut(value) {
        this.alterDialogBool = true
      },


      // 操作块-编辑-对话框关闭回调
      alterHandleClose() {
        this.alterDialogBool = false
        this.$refs.alterFormRef.resetFields()
        this.alterRuleForm = {}
      },


      // 操作块-编辑-表单的级连选择器（省市区/县）
      cityDataHandleChange(value) {
        // 外部引入的组件：citydata.js
        this.alterRuleForm.city = value
      },


      // 操作块-位置按钮点击
      transportDialogBut(value) {
        // this.$http.get(`/kuaidi/:id`)  查看物流信息的接口有问题。做个假数据
        this.transportList = {
          "data": [{
              "time": "2018-05-10 09:39:00",
              "ftime": "2018-05-10 09:39:00",
              "context": "已签收,感谢使用顺丰,期待再次为您服务",
              "location": ""
            },
            {
              "time": "2018-05-10 08:23:00",
              "ftime": "2018-05-10 08:23:00",
              "context": "[北京市]北京海淀育新小区营业点派件员 顺丰速运 95338正在为您派件",
              "location": ""
            },
            {
              "time": "2018-05-10 07:32:00",
              "ftime": "2018-05-10 07:32:00",
              "context": "快件到达 [北京海淀育新小区营业点]",
              "location": ""
            },
            {
              "time": "2018-05-10 02:03:00",
              "ftime": "2018-05-10 02:03:00",
              "context": "快件在[北京顺义集散中心]已装车,准备发往 [北京海淀育新小区营业点]",
              "location": ""
            },
            {
              "time": "2018-05-09 23:05:00",
              "ftime": "2018-05-09 23:05:00",
              "context": "快件到达 [北京顺义集散中心]",
              "location": ""
            },
            {
              "time": "2018-05-09 21:21:00",
              "ftime": "2018-05-09 21:21:00",
              "context": "快件在[北京宝胜营业点]已装车,准备发往 [北京顺义集散中心]",
              "location": ""
            },
            {
              "time": "2018-05-09 13:07:00",
              "ftime": "2018-05-09 13:07:00",
              "context": "顺丰速运 已收取快件",
              "location": ""
            },
            {
              "time": "2018-05-09 12:25:03",
              "ftime": "2018-05-09 12:25:03",
              "context": "卖家发货",
              "location": ""
            },
            {
              "time": "2018-05-09 12:22:24",
              "ftime": "2018-05-09 12:22:24",
              "context": "您的订单将由HLA（北京海淀区清河中街店）门店安排发货。",
              "location": ""
            },
            {
              "time": "2018-05-08 21:36:04",
              "ftime": "2018-05-08 21:36:04",
              "context": "商品已经下单",
              "location": ""
            }
          ],
          "meta": {
            "status": 200,
            "message": "获取物流信息成功！"
          }
        }

        if (this.transportList.meta.status === 200) {
          this.transportList = this.transportList.data
          this.transportBool = true
        } else {
          this.$message.error("获取物流信息失败！")
          this.transportBool = false
        }

      },

      // 操作块-位置-物流信息对话框的关闭回调
      transportHandleClose() {
        this.transportBool = false

      },
    }
  }

</script>

<style lang="less" scoped>
  
</style>
